package itheima.com.stream2;

import itheima.com.stream.Student;

import java.util.*;
import java.util.stream.Collectors;

public class Test2 {
    public static void main(String[] args) {
        //准备测试数据：
        List<Student> students = new ArrayList<>();
        students.add(new Student("小王", 18, 66.0));
        students.add(new Student("小张", 17, 99.0));
        students.add(new Student("小李李", 26, 20.0));
        students.add(new Student("小赵", 16, 77.0));
        students.add(new Student("小刘刘", 19, 18.0));
        students.add(new Student("小李", 26, 20.0));
        long count = students.stream()
                .filter(student -> student.getName().length() == 3)
                .count();
        System.out.println(count);

        Optional<Student> min = students.stream()
                .min((s1, s2) -> Double.compare(s1.getScore(), s2.getScore()));
        System.out.println(min.get());
        System.out.println("===========================");
        List<Student> collect = students.stream()
                .filter(student -> student.getScore() < 60.0)
                .collect(Collectors.toList());
        System.out.println(collect);
        System.out.println("===========================");
        Set<Student> collect1 = students.stream()
                .filter(student -> student.getScore() < 60.0)
                .collect(Collectors.toSet());
        System.out.println(collect1);

        System.out.println("===========================");
        Map<String, Student> collect2 = students.stream()
                .filter(student -> student.getScore() < 60.0)
                .collect(Collectors.toMap(s -> s.getName(), s -> s));
        collect2.forEach((s, student) -> System.out.println(s + "---" + student));
    }
}
